
package server.events;



import client.MapleCharacter;
import server.Timer;
import tools.MaplePacketCreator;

import java.util.concurrent.ScheduledFuture;






 public class MapleFitness
         extends MapleEvent
         {
    /*  11 */   private final long time = 600000L;
    /*  12 */   private long timeStarted = 0L;
    private ScheduledFuture<?> fitnessSchedule;
       private ScheduledFuture<?> msgSchedule;



    public MapleFitness(int channel, MapleEventType type) {
        /*  16 */
        super(channel, type);

    }




    public void finished(MapleCharacter chr) {
        /*  21 */
        givePrize(chr);
        /*  22 */
        chr.finishAchievement(20);

    }




    public void onMapLoad(MapleCharacter chr) {
        /*  27 */
        super.onMapLoad(chr);
        /*  28 */
        if (isTimerStarted()) {
            /*  29 */
            chr.send(MaplePacketCreator.getClock((int) (getTimeLeft() / 1000L)));

        }

    }




    public void startEvent() {
        /*  35 */
        unreset();
        /*  36 */
        super.reset();
        /*  37 */
        broadcast(MaplePacketCreator.getClock(600));
        /*  38 */
        this.timeStarted = System.currentTimeMillis();
        /*  39 */
        checkAndMessage();

        /*  41 */
        getClass();
        this.fitnessSchedule = Timer.EventTimer.getInstance().schedule(() -> {
            for (int i = 0; i < this.type.mapids.length; i++) {
                for (MapleCharacter chr : getMap(i).getCharactersThreadsafe()) warpBack(chr);
            }
            unreset();
        }, 600000L);







        /*  49 */
        broadcast(MaplePacketCreator.serverNotice(0, "The portal has now opened. Press the up arrow key at the portal to enter."));

    }



    public boolean isTimerStarted() {
        /*  53 */
        return (this.timeStarted > 0L);

    }



    public long getTime() {
        /*  57 */
        return 600000L;

    }



    public void resetSchedule() {
        /*  61 */
        this.timeStarted = 0L;
        /*  62 */
        if (this.fitnessSchedule != null) {
            /*  63 */
            this.fitnessSchedule.cancel(false);

        }
        /*  65 */
        this.fitnessSchedule = null;
        /*  66 */
        if (this.msgSchedule != null) {
            /*  67 */
            this.msgSchedule.cancel(false);

        }
        /*  69 */
        this.msgSchedule = null;

    }




    public void reset() {
        /*  74 */
        super.reset();
        /*  75 */
        resetSchedule();
        /*  76 */
        getMap(0).getPortal("join00").setPortalState(false);

    }




    public void unreset() {
        /*  81 */
        super.unreset();
        /*  82 */
        resetSchedule();
        /*  83 */
        getMap(0).getPortal("join00").setPortalState(true);

    }



    public long getTimeLeft() {
        /*  87 */
        return 600000L - System.currentTimeMillis() - this.timeStarted;

    }



    public void checkAndMessage() {
        /*  91 */
        this.msgSchedule = Timer.EventTimer.getInstance().register(() -> {
            long timeLeft = getTimeLeft();
            if (timeLeft > 9000L && timeLeft < 11000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "You have 10 sec left. Those of you unable to beat the game, we hope you beat it next time! Great job everyone!! See you later~"));
            } else if (timeLeft > 11000L && timeLeft < 101000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "Alright, you don't have much time remaining. Please hurry up a little!"));
            } else if (timeLeft > 101000L && timeLeft < 201000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "The 4th stage is the last one for [The Maple Physical Fitness Test]. Please don't give up at the last minute and try your best. The reward is waiting for you at the very top!"));
            } else if (timeLeft > 201000L && timeLeft < 301000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "The 3rd stage offers traps where you may see them, but you won't be able to step on them. Please be careful of them as you make your way up."));
            } else if (timeLeft > 301000L && timeLeft < 361000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "For those who have heavy lags, please make sure to move slowly to avoid falling all the way down because of lags."));
            } else if (timeLeft > 361000L && timeLeft < 501000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "Please remember that if you die during the event, you'll be eliminated from the game. If you're running out of HP, either take a potion or recover HP first before moving on."));
            } else if (timeLeft > 501000L && timeLeft < 601000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "The most important thing you'll need to know to avoid the bananas thrown by the monkeys is *Timing* Timing is everything in this!"));
            } else if (timeLeft > 601000L && timeLeft < 661000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "The 2nd stage offers monkeys throwing bananas. Please make sure to avoid them by moving along at just the right timing."));
            } else if (timeLeft > 661000L && timeLeft < 701000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "Please remember that if you die during the event, you'll be eliminated from the game. You still have plenty of time left, so either take a potion or recover HP first before moving on."));
            } else if (timeLeft > 701000L && timeLeft < 781000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "Everyone that clears [The Maple Physical Fitness Test] on time will be given an item, regardless of the order of finish, so just relax, take your time, and clear the 4 stages."));
            } else if (timeLeft > 781000L && timeLeft < 841000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "There may be a heavy lag due to many users at stage 1 all at once. It won't be difficult, so please make sure not to fall down because of heavy lag."));
            } else if (timeLeft > 841000L) {
                broadcast(MaplePacketCreator.serverNotice(0, "[MapleStory Physical Fitness Test] consists of 4 stages, and if you happen to die during the game, you'll be eliminated from the game, so please be careful of that."));
            }
        }, 60000L);

    }

}


/* Location:              C:\PGX\Server.jar!\server\events\MapleFitness.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */